package com.beadhouse.nurrecord.support.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beadhouse.common.dto.QueryResult;
import com.beadhouse.common.exeption.BeadHouseException;
import com.beadhouse.entity.CustomerAndNurcontentEntity;
import com.beadhouse.nurrecord.ao.NursingProjectAo;
import com.beadhouse.nurrecord.dao.NursingRecordsDao;
import com.beadhouse.nurrecord.service.NursingRecordsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class NursingRecordsServiceImpl implements NursingRecordsService{

	@Autowired
	NursingRecordsDao dao;
	
	@Override
	public QueryResult<CustomerAndNurcontentEntity> selectRecord(NursingProjectAo ao) throws Exception {
		int pageNo = Integer.parseInt(ao.getPageNo()) ;
		int pageSize = Integer.parseInt(ao.getPageSize()) ;
		PageHelper.startPage(pageNo, pageSize);
		List<CustomerAndNurcontentEntity> rows = dao.select(ao.getCustomerId());
		
		QueryResult<CustomerAndNurcontentEntity> result = new QueryResult<>();
		PageInfo<CustomerAndNurcontentEntity> page = new PageInfo<>(rows);
		result.setPageNo(pageNo);
		result.setPageSize(pageSize);
		result.setRows(rows);
		result.setTotalRows((int)page.getTotal());
		result.setTotalPages(result.getTotalPages());
		return result;
	}

	@Override
	public void deleteRecord(String customerId,String nurContentId) throws Exception {
		if(customerId==null) {
			throw new BeadHouseException("客户id不能为空");
		}
		if(nurContentId==null) {
			throw new BeadHouseException("护理内容id不能为空");
		}
		int cusId =Integer.parseInt(customerId) ;
		int nurId = Integer.parseInt(nurContentId);
		Map<String, Object> map = new HashMap<>();
		map.put("status", 0);
		dao.updateOne(cusId, nurId,map);
	}
	
}
